change to pass in the cursor direction always, not just when we need an
authorHavoc Pennington <hp@pobox.com>
Mon, 25 Feb 2002 04:19:05 +0000 (04:19 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Mon, 25 Feb 2002 04:19:05 +0000 (04:19 +0000)
2002-02-24  Havoc Pennington  <hp@pobox.com>

* gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
the cursor direction always, not just when we need an arrow, so we
can flip the cursor around its axis for RTL. Resolves #72372

* gtk/gtkentry.c (gtk_entry_draw_cursor): update for
draw_insertion_cursor change

* gtk/gtklabel.c (gtk_label_draw_cursor): ditto

* gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto

12 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkentry.c
gtk/gtklabel.c
gtk/gtkstyle.c
gtk/gtkstyle.h
gtk/gtktextdisplay.c

index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 6447bb3e89a155f9e3dd5bd3a7405a7b6057a407..9ab9b6c5f06c9c7883452dcf045635756ca279f7 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
+       the cursor direction always, not just when we need an arrow, so we
+       can flip the cursor around its axis for RTL. Resolves #72372
+
+       * gtk/gtkentry.c (gtk_entry_draw_cursor): update for
+       draw_insertion_cursor change
+       
+       * gtk/gtklabel.c (gtk_label_draw_cursor): ditto
+
+       * gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
+       
 2002-02-24  Alexander Larsson  <alla@lysator.liu.se>
 
        * gdk/x11/gdkwindow-x11.c (gdk_window_set_background):
index 5a847e9a8826cfb2bb559aa9ddd53965be08132b..3a4dcfbaa9c17a572c44496fb44acfc58cbf85e7 100644 (file)
@@ -2701,6 +2701,8 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
                    "gtk-split-cursor", &split_cursor,
                    NULL);
 
+      dir1 = widget_direction;
+      
       if (split_cursor)
        {
          gc1 = entry->cursor_gc;
@@ -2708,7 +2710,6 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
 
          if (weak_x != strong_x)
            {
-             dir1 = widget_direction;
              dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR;
              
              gc2 = widget->style->text_gc[GTK_STATE_NORMAL];
@@ -2731,13 +2732,15 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
       cursor_location.height = text_area_height - 2 * INNER_BORDER ;
       
       _gtk_draw_insertion_cursor (widget, entry->text_area, gc1,
-                                 &cursor_location, dir1);
+                                 &cursor_location, dir1,
+                                  dir2 != GTK_TEXT_DIR_NONE);
       
-      if (gc2)
+      if (dir2 != GTK_TEXT_DIR_NONE)
        {
          cursor_location.x = xoffset + x2;
          _gtk_draw_insertion_cursor (widget, entry->text_area, gc2,
-                                     &cursor_location, dir2);
+                                     &cursor_location, dir2,
+                                      TRUE);
        }
     }
 }
index 5341d749f7b4517dbb4a59806ced9bc87f94459b..8538e458f7ccdb4bb5bbe3c52c5c54f7f1fdf4ea 100644 (file)
@@ -1694,6 +1694,8 @@ gtk_label_draw_cursor (GtkLabel  *label, gint xoffset, gint yoffset)
                    "gtk-split-cursor", &split_cursor,
                    NULL);
 
+      dir1 = widget_direction;
+      
       if (split_cursor)
        {
          gc1 = label->select_info->cursor_gc;
@@ -1702,7 +1704,6 @@ gtk_label_draw_cursor (GtkLabel  *label, gint xoffset, gint yoffset)
          if (strong_pos.x != weak_pos.x ||
              strong_pos.y != weak_pos.y)
            {
-             dir1 = widget_direction;
              dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR;
              
              gc2 = widget->style->black_gc;
@@ -1725,9 +1726,10 @@ gtk_label_draw_cursor (GtkLabel  *label, gint xoffset, gint yoffset)
       cursor_location.height = PANGO_PIXELS (cursor1->height);
       
       _gtk_draw_insertion_cursor (widget, widget->window, gc1,
-                                 &cursor_location, dir1);
+                                 &cursor_location, dir1,
+                                  dir2 != GTK_TEXT_DIR_NONE);
       
-      if (gc2)
+      if (dir2 != GTK_TEXT_DIR_NONE)
        {
          cursor_location.x = xoffset + PANGO_PIXELS (cursor2->x);
          cursor_location.y = yoffset + PANGO_PIXELS (cursor2->y);
@@ -1735,7 +1737,7 @@ gtk_label_draw_cursor (GtkLabel  *label, gint xoffset, gint yoffset)
          cursor_location.height = PANGO_PIXELS (cursor2->height);
          
          _gtk_draw_insertion_cursor (widget, widget->window, gc2,
-                                     &cursor_location, dir2);
+                                     &cursor_location, dir2, TRUE);
        }
     }
 }
index eca446b3d038e7b15ad094d2a414bc8a61ebd8ad..beef9abb4dff4d094b3a0cddab8eb7763d8893ae 100644 (file)
@@ -5668,9 +5668,10 @@ gtk_style_set_font (GtkStyle *style,
  * @drawable: a #GdkDrawable
  * @gc: a #GdkGC
  * @location: location where to draw the cursor (@location->width is ignored)
- * @dir: text direction for the cursor, used to decide whether to draw a
- *       directional arrow on the cursor and in what direction. Unless both
- *       strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
+ * @direction: whether the cursor is left-to-right or
+ *             right-to-left. Should never be #GTK_TEXT_DIR_NONE
+ * @draw_arrow: %TRUE to draw a directional arrow on the
+ *        cursor. Should be %FALSE unless the cursor is split.
  * 
  * Draws a text caret on @drawable at @location. This is not a style function
  * but merely a convenience function for drawing the standard cursor shape.
@@ -5680,48 +5681,61 @@ _gtk_draw_insertion_cursor (GtkWidget        *widget,
                            GdkDrawable      *drawable,
                            GdkGC            *gc,
                            GdkRectangle     *location,
-                           GtkTextDirection  dir)
+                            GtkTextDirection  direction,
+                            gboolean          draw_arrow)
 {
   gint stem_width;
   gint arrow_width;
   gint x, y;
   gint i;
   gfloat cursor_aspect_ratio;
-
+  gint offset;
+  
+  g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
+  
   gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
   
   stem_width = location->height * cursor_aspect_ratio + 1;
   arrow_width = stem_width + 1;
+
+  /* put (stem_width % 2) on the proper side of the cursor */
+  if (direction == GTK_TEXT_DIR_LTR)
+    offset = stem_width / 2;
+  else
+    offset = stem_width - stem_width / 2;
+  
   for (i = 0; i < stem_width; i++)
     gdk_draw_line (drawable, gc,
-                  location->x + i - stem_width / 2, location->y,
-                  location->x + i - stem_width / 2, location->y + location->height - 1);
+                  location->x + i - offset, location->y,
+                  location->x + i - offset, location->y + location->height - 1);
 
-  if (dir == GTK_TEXT_DIR_RTL)
+  if (draw_arrow)
     {
-      x = location->x - stem_width / 2 - 1;
-      y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+      if (direction == GTK_TEXT_DIR_RTL)
+        {
+          x = location->x - offset - 1;
+          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
   
-      for (i = 0; i < arrow_width; i++)
-       {
-         gdk_draw_line (drawable, gc,
-                        x, y + i + 1,
-                        x, y + 2 * arrow_width - i - 1);
-         x --;
-       }
-    }
-  else if (dir == GTK_TEXT_DIR_LTR)
-    {
-      x = location->x + stem_width - stem_width / 2;
-      y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+          for (i = 0; i < arrow_width; i++)
+            {
+              gdk_draw_line (drawable, gc,
+                             x, y + i + 1,
+                             x, y + 2 * arrow_width - i - 1);
+              x --;
+            }
+        }
+      else if (direction == GTK_TEXT_DIR_LTR)
+        {
+          x = location->x + stem_width - offset;
+          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
   
-      for (i = 0; i < arrow_width; i++) 
-       {
-         gdk_draw_line (drawable, gc,
-                        x, y + i + 1,
-                        x, y + 2 * arrow_width - i - 1);
-         x++;
-       }
+          for (i = 0; i < arrow_width; i++) 
+            {
+              gdk_draw_line (drawable, gc,
+                             x, y + i + 1,
+                             x, y + 2 * arrow_width - i - 1);
+              x++;
+            }
+        }
     }
 }
index 9c3d60384e51720f79cebb2f090a38b5920903cd..02b8a6e27b8a9146d54496472d74a70fe1b7ae1f 100644 (file)
@@ -883,7 +883,8 @@ void _gtk_draw_insertion_cursor (GtkWidget        *widget,
                                 GdkDrawable      *drawable,
                                 GdkGC            *gc,
                                 GdkRectangle     *location,
-                                GtkTextDirection  dir);
+                                 GtkTextDirection  direction,
+                                 gboolean          draw_arrow);
 
 #ifdef __cplusplus
 }
index b3acdab830d9b62946e51651dcafebe50661b85d..cfb5225d747daf9ce107a50f96bc3d1b937c9c31 100644 (file)
@@ -842,16 +842,12 @@ gtk_text_layout_draw (GtkTextLayout *layout,
               else
                 gc = widget->style->text_gc[GTK_STATE_NORMAL];
 
+              dir = line_display->direction;
              if (have_strong && have_weak)
                {
-                 dir = line_display->direction;
                  if (!cursor->is_strong)
                    dir = (dir == GTK_TEXT_DIR_RTL) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
                }
-             else
-               {
-                 dir = GTK_TEXT_DIR_NONE;
-               }
  
              cursor_location.x = line_display->x_offset + cursor->x - x_offset;
              cursor_location.y = current_y + line_display->top_margin + cursor->y;
@@ -859,7 +855,8 @@ gtk_text_layout_draw (GtkTextLayout *layout,
              cursor_location.height = cursor->height;
  
              gdk_gc_set_clip_rectangle(gc, &clip);
-             _gtk_draw_insertion_cursor (widget, drawable, gc, &cursor_location, dir);
+             _gtk_draw_insertion_cursor (widget, drawable, gc, &cursor_location,
+                                          dir, have_strong && have_weak);
               gdk_gc_set_clip_rectangle (gc, NULL);
 
               cursor_list = cursor_list->next;